package com.sloera.jvm.oom;

import java.util.concurrent.TimeUnit;

/**
 * @author sloera
 * @create 2020/5/3
 * i=161410
 * Exception in thread "main" java.lang.OutOfMemoryError: unable to create new native thread
 */
public class UnableCreateNewThreadDemo {
    public static void main(String[] args) {
        for (int i = 0; ; i++) {
            System.out.println("i=" + (i + 1));
            new Thread(() -> {
                //暂停一会线程
                try {
                    TimeUnit.SECONDS.sleep(Integer.MAX_VALUE);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }, String.valueOf(i + 1)).start();
        }
    }
}
